<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/js/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/static/js/jquery/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/static/js/layui/layui.js"></script>
</head>
<body>
<div class="layui-tab layui-tab-brief">
    <div class="layui-col-md2 layui-col-md-offset1">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-block">
                    <input type="text" name="title" id="name" style="width: 200px;" lay-verify="title" autocomplete="off" placeholder="姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-block">
                    <input type="text" name="title" id="username" style="width: 200px;" lay-verify="title" autocomplete="off" placeholder="用户名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">登录密码：</label>
                <div class="layui-input-block">
                    <input type="text" name="title" id="password" style="width: 200px;" lay-verify="title" autocomplete="off" placeholder="登录密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 80px">隶属部门</label>
                <div class="layui-input-inline " id="department" style="overflow: visible; width: 180px">
                    <select name="modules" style="width: 200px" class="department" lay-verify="required" lay-search="">
                        <option value="">直接选择或搜索</option>
                        <option value="1">采购部门</option>
                        <option value="2">销售部门</option>
                    </select>
                </div>
            </div>
            <div style="width: 320px; text-align: center">
                <div class="layui-btn-container">
                    <button type="button" id="btn" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal">确认添加</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    // layui.use(['form', 'layedit', 'laydate'], function(){
    //     var form = layui.form
    //         ,layer = layui.layer
    //         ,layedit = layui.layedit
    //         ,laydate = layui.laydate;
    // });
    $(function () {
        $("#btn").click(function(){
            if ($("#name").val()==''){
                layer.msg("请输入姓名");
                return;
            }
            if ($("#username").val()==''){
                layer.msg("请输入登录名");
                return;
            }
            if ($("#password").val()==""){
                layer.msg("请输入密码");
                return;
            }
            if ($("#department").find("option:selected").text()=="直接选择或搜索"){
                layer.msg("请选择部门");
                return;
            }
            var param = {"name":$("#name").val(),"username":$("#username").val(),"password":$("#password").val(),"department":$("#department").find("option:selected").text()}
            console.log(param);
            $.ajax({
                url:"/main/manage/insert/user",
                data:param,
                dataType:"json",
                success:function (data){
                    // console.log(data);
                    if (data==1){
                        layer.msg("添加成功");
                        setTimeout(function (){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        },1500);
                    }else if (data==2){
                        layer.msg("此人已存在");
                    }else {
                        layer.msg("发生什么事了！！");
                    }
                }
            })
        });
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
            return;
        }
    });
</script>
</body>
</html>